package com.vecharm.app.ui.cloudshelf

import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import com.ling.sdk.app.App
import com.ling.sdk.ui.BaseFragment
import com.vecharm.app.R
import com.vecharm.app.bean.Goods
import com.vecharm.app.bean.GoodsBean
import com.vecharm.app.utils.url
import kotlinx.android.synthetic.main.fragment_banner_detail.*

class BannerDetailFragment : BaseFragment() {


    override fun getLayoutId() = R.layout.fragment_banner_detail

    override fun onInitView() {

        val views = ArrayList<View>()
        val goods: Goods = arguments?.getSerializable("goods") as? Goods ?: Goods()
        goods.showUrl?.forEach {
            val imageView = ImageView(App.app)
            imageView.url(App.app, it)
            imageView.scaleType = ImageView.ScaleType.FIT_XY
            imageView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
            views.add(imageView)
        }


        (decent_banner.layoutParams as LinearLayout.LayoutParams).apply { this.weight = goods.bannerDetailPagePercent; decent_banner.layoutParams = this }
        (container.layoutParams as LinearLayout.LayoutParams).apply { this.weight = 1 - goods.bannerDetailPagePercent; container.layoutParams = this }


        decent_banner.start(views, emptyList(), goods.bannerLoopInterval, goods.bannerAnimationDuration)

        if (goods.fullBanner) {
            container.visibility = View.GONE
            return
        }

        if (goods.detailImage != null) {
            detailImage.visibility = View.VISIBLE
            detailImage.url(App.app, goods.detailImage)
            return
        }

        title.text = goods.title
        subTitle.text = goods.subTitle
        form.text = goods.form
        detail.text = goods.description

    }


}